﻿using System;
using System.Web.Mvc;
using RefLib.MVC.Util;

namespace RefLib.MVC
{
    public static class jqViewContextExtension
    {
        public static MvcHtmlString jqViewContext(this HtmlHelper helper)
        {
            var sb = new ScriptBuilder();
            sb.AddLine("var jqViewContext = new Object();");
            foreach (string key in helper.ViewContext.RouteData.Values.Keys)
            {
                sb.AddLine(String.Format("jqViewContext.{0} = \"{1}\";", key, helper.ViewContext.RouteData.Values[key]));
            }
            return new MvcHtmlString(sb.GetScriptBlock());
        }
    }
}
